#ifndef _THREAD_H_
#define _THREAD_H_

#include <js/jsapi.h>
#include <prlock.h>

typedef struct {
	unsigned int slot;
	int state;
	JSContext *cx;
	PRLock *lock;
	unsigned long branch_callback_counter;
	//JSContext *parent_cx;
	jsval func;
	jsval *argv;
	int argc;
	int delay;
	JSObject *global;
	JSObject *thisObj;
	PRThread *thread;
	//pthread_t tid;
	uint32 t;
	jsval rval;
	unsigned long id;	
	PRFileDesc *client;
	PRFileDesc *socket;
	PRThread *join;
	int closed;
	char *document_root;
} js_thread_t;


typedef struct {
	PRLock *lock;
	unsigned long last_id;
	js_thread_t **slots;
	unsigned int nslots;
} threadpool_t;



void init_threadpool();

void init_thread_context(js_thread_t *x);


void js_thread_proc(void *param);

js_thread_t *get_thread_slot(JSContext *cx);

//int close_js_thread(int id);

PRThread *create_js_thread(JSContext *cx, PRFileDesc *client, jsval func, char *header);



#endif /* _THREAD_H_ */

